{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Ammsqa2"

// By ArtemQa146

const
    Process = 8@ //   

    render_weapon = 25@
    anim_char_int = 10@v
    anim_char_idle = 15@v
    anim_char_out = 20@v

    //  Z    
    Position_Z_1 = 0.55
    Position_Z_2 = 0.05
    Position_Z_3 = -0.45

    //       
    Move_Weapon_Step = 60
    Move_Weapon_Step_2 = 120
end

//          .
// $AMMU_SELECTED_WEAPON_MODEL -     
// $AMMU_STAGE - 2 -  , 4 -           ,
//                                  5 -   , 6 - , 7 -     
// $AMMU_SELLER_ANIMATION_TIME -  ,   
// $9633 -  .     id     .
//                                    ,    col45,   $9633 == 22

repeat
wait 0
04ED: load_animation  "AmmoSellQa"
until 04EE:   animation "AmmoSellQa" loaded

        Process = 0 //  

        016A: fade 1 time 300 //  

        repeat
        wait 0
        if
            player.Defined(0)
        then
            06AB: set_actor $player_actor all_weapons_hidden 1

            gosub @Camera_Position
            
            if and
                Process == 0
                $AMMU_STAGE == 6
                $AMMU_SELLER_ANIMATION_TIME > 0.8
            then
                1@ = 0
                
                0E84: get_weaponinfo $AMMU_Selected_Weapon skill 0 store_to 1@
                if
                    1@ <> 0
                then
                    0E8A: get_weaponinfo_slot 1@ store_to 2@
                else
                    0E84: get_weaponinfo $AMMU_Selected_Weapon skill 1 store_to 1@
                    if
                        1@ <> 0
                    then
                        0E8A: get_weaponinfo_slot 1@ store_to 2@
                    else
                        0E84: get_weaponinfo $AMMU_Selected_Weapon skill 2 store_to 1@
                        if
                            1@ <> 0
                        then
                            0E8A: get_weaponinfo_slot 1@ store_to 2@
                        end
                    end
                end
            
                06D2: anim_char_int = "pistol_int"
                06D2: anim_char_idle = "pistol_idle"
                06D2: anim_char_out = "pistol_out"
                
                if
                    2@ == 2
                then
                    06D2: anim_char_int = "pistol_int"
                    06D2: anim_char_idle = "pistol_idle"
                    06D2: anim_char_out = "pistol_out"
                end
                
                if or
                    2@ == 5
                    2@ == 6
                    2@ == 7
                then
                    06D2: anim_char_int = "rifle_int"
                    06D2: anim_char_idle = "rifle_idle"
                    06D2: anim_char_out = "rifle_out"
                end
                
                if
                    2@ == 8
                then
                    06D2: anim_char_int = "grenade_int"
                    06D2: anim_char_idle = "grenade_idle"
                    06D2: anim_char_out = "grenade_out"
                end
                
                if
                    2@ == 4
                then
                    06D2: anim_char_int = "uzi_int"
                    06D2: anim_char_idle = "uzi_idle"
                    06D2: anim_char_out = "uzi_out"
                end
                
                if
                    2@ == 3
                then
                    06D2: anim_char_int = "shotgun_int"
                    06D2: anim_char_idle = "shotgun_idle"
                    06D2: anim_char_out = "shotgun_out"
                end
                
                if
                    $AMMU_SELECTED_WEAPON_MODEL == 350
                then
                    06D2: anim_char_int = "sawnoff_int"
                    06D2: anim_char_idle = "sawnoff_idle"
                    06D2: anim_char_out = "sawnoff_out"
                end
                
                if
                    $AMMU_SELECTED_WEAPON_MODEL == 353
                then
                    06D2: anim_char_int = "smg_int"
                    06D2: anim_char_idle = "smg_idle"
                    06D2: anim_char_out = "smg_out"
                end
                
                if
                    $AMMU_SELECTED_WEAPON_MODEL == 373
                then
                    06D2: anim_char_int = "armor_int"
                    06D2: anim_char_idle = "armor_idle"
                    06D2: anim_char_out = "rifle_out"
                end
                
                0615: define_AS_pack_begin 1@
                0812: AS_actor -1 perform_animation anim_char_int IFP "AmmoSellQa" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                0812: AS_actor -1 perform_animation anim_char_idle IFP "AmmoSellQa" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                0616: define_AS_pack_end 1@
                0618: assign_actor $PLAYER_ACTOR to_AS_pack 1@
                061B: remove_references_to_AS_pack 1@
                
                
                Process = 1
            end
            
            if and
                Process == 1
                0611:   actor $PLAYER_ACTOR performing_animation anim_char_int
            then
                0613: 1@ = actor $PLAYER_ACTOR animation anim_char_int time
                if
                    1@ > 0.5
                then
                    0085: 1@ = $AMMU_SELECTED_WEAPON_MODEL // (int)
                    model.Load(1@)
                    038B: load_requested_models
                    0E2E: create_render_object_to_char_bone $PLAYER_ACTOR model 1@ bone 24 offset 0 0 0 rotation 0 0 0 store_to render_weapon
                    model.Destroy(1@)
                    Process = 2
                end
            end
            
            if and
                Process == 2
                $AMMU_STAGE == 7
            then
                Process = 3
            end
            
            if and
                $AMMU_SELLER_ANIMATION_TIME >= 0.1
                Process == 3
            then
                Process = 4
                0615: define_AS_pack_begin 1@
                0812: AS_actor -1 perform_animation anim_char_out IFP "AmmoSellQa" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                0616: define_AS_pack_end 1@
                0618: assign_actor $PLAYER_ACTOR to_AS_pack 1@
                061B: remove_references_to_AS_pack 1@
            end
            
            if and
                Process == 4
                0611:   actor $PLAYER_ACTOR performing_animation anim_char_out
            then
                0613: 1@ = actor $PLAYER_ACTOR animation anim_char_out time
                if
                    1@ > 0.5
                then
                    0E2F: delete_render_object render_weapon
                    Process = 5
                end
            end
            
            if and
                Process == 5
                $AMMU_STAGE == 6
            then
                Process = 0
                0687: clear_actor $PLAYER_ACTOR task
            end

        // 
        if and
            $AMMU_STAGE == 5 //   
            00E1:   player 0 pressed_key 15
        then
            break
        end

        //     -    ,   .
        else
            break
        end
        until $AMMU_STAGE == 2 // 2 -                   
        02EB: restore_camera_with_jumpcut
        0687: clear_actor $PLAYER_ACTOR task
        04EF: release_animation "AmmoSellQa"
        0A93: terminate_this_custom_script



//       
:Camera_Position
if and
    Process > 0
    $AMMU_STAGE >= 6
then
    04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.4 1.55 0.4
    04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.1 0.0 0.3
    if
        0611:   actor $PLAYER_ACTOR performing_animation anim_char_int
    then
        0613: 7@ = actor $PLAYER_ACTOR animation anim_char_int time
        if and
            not $AMMU_SELECTED_WEAPON_MODEL == 373
            7@ <= 0.5
        then
            04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.3 1.1 0.4
            04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.1 0.0 0.4
        else
            if and
                $AMMU_SELECTED_WEAPON_MODEL == 373
                7@ < 0.7
            then
                04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.5 0.8 0.5
                04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.15 0.0 0.4
            end
        end
    end
    if
        0611:   actor $PLAYER_ACTOR performing_animation anim_char_out
    then
        0613: 7@ = actor $PLAYER_ACTOR animation anim_char_out time
        if
            7@ <= 0.5
        then
            04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.3 1.1 0.4
            04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.1 0.0 0.4
            if $AMMU_SELECTED_WEAPON_MODEL == 373
            then
                04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.5 0.8 0.5
                04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.15 0.0 0.4
            end
        end
    end
    015F: set_camera_position 1@ 2@ 3@ rotation 0.0 0.0 0.0
    0160: set_camera_point_at 4@ 5@ 6@ switchstyle 2
else
    015F: set_camera_position $X_Camera $Y_Camera $Z_Camera rotation 0.0 0.0 0.0
    0160: set_camera_point_at $AMMU_X_Aim_Camera $AMMU_Y_Aim_Camera $AMMU_Z_Aim_Camera switchstyle 2
end
return
